<?php

	require_once ($_SERVER['DOCUMENT_ROOT']."/Auditing/data/config.php");
	require_once ($_SERVER['DOCUMENT_ROOT']."/Auditing/data/DBConn.php");

	function retrieveMenus($userId){
		
		$temp="";
		
		$query ="select page_id from ota_role where user_id=".$userId;
//		echo $query;	
		$result = mysql_query($query); 
		$i=0;
		while ($row = mysql_fetch_array($result)) {
			
			if($i!=0){
				$temp = $temp.",";
			}
			$temp =$temp.$row['page_id'];
			$i++;			
		}
		
		$query = "select * from ota_page where page_id in (".$temp.") order by page_parent_id";
//		echo $query;
		$result = mysql_query($query); 
		$pages;
		
		if ($result!=NULL) {

			$i=0;	
			while ($row = mysql_fetch_array($result)) {
				
				$pages[$i][0]=$row['page_id'];
				$pages[$i][1]=$row['description'];
				$pages[$i][2]=$row['page_parent_id'];
				$pages[$i][3]=$row['url'];
				$i++;
			}
				
		}
		
		return $pages;
	}
	
	function retrieveMenuHeaders($menus){
		
		$temp="";
				

		for($j=0;$j<sizeOf($menus);$j++){
			
			if($j!=0){
				$temp = $temp.",";
			}
			$temp= $temp.$menus[$j][0];
				
		}
//		echo $temp;
		
		
		$query ="select * from ota_page where page_id IN(select distinct page_parent_id from ota_page where page_id IN(".$temp."))";
//		echo $query;
		$result = mysql_query($query);
		$pages; 
		if ($result!=NULL) {

			$i=0;	
			while ($row = mysql_fetch_array($result)) {
				
				$pages[$i][0]=$row['page_id'];
				$pages[$i][1]=$row['description'];
				$pages[$i][2]=$row['page_parent_id'];
				$pages[$i][3]=$row['url'];
				$i++;	
			}
		
		}
		return $pages;
	}
?>